.section .data	
	file:
		.string "data.txt"
	str:
		.string "保存文件成功\n"
.section .bss 
	.lcomm filehandle,4
.equ SYS_WRITE,1
.equ SYS_OPEN,2
.equ SYS_CLOSE,3
.equ PERSON_SIZE,76
.section .text
.global SaveContact
.type SaveContact,@function
SaveContact:
	nop
	push %rbp
	mov %rsp,%rbp
	subq $8,%rsp	
	mov %rdi,-8(%rbp)
	mov -8(%rbp),%rbx
#打开文件
	mov $SYS_OPEN,%rax
	mov $file,%rdi
	mov $0102,%rsi
	mov $0664,%rdx
	syscall
	test %rax,%rax
	js 1f
#获取文件句柄
	movl %eax,filehandle
#获取通讯录大小
	movl 12(%rbx),%r8d
	imull $PERSON_SIZE,%r8d
#将堆区数据写入文件
	movq $SYS_WRITE,%rax
	movl filehandle,%edi
	movq (%rbx),%rsi
	movl %r8d,%edx
	syscall
	test %rax,%rax
	js 1f
#关闭文件
	mov $SYS_CLOSE,%rax
	mov filehandle,%edi
	syscall
#打印提示信息
	mov $0,%rax
	mov $str,%rdi
	call printf			
1:
	leaveq 	
	retq
